<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <script>
      //1
      let arr = []
      while (arr.length < 5) {
        let age = +prompt(`请输入年龄（0-100）（第${arr.length + 1}个）`)

        if (age > 0 && age <= 100) {
          arr.push(age)
        } else {
          alert('请输入正确年龄')
        }
      }
      console.log(arr)
      //2
        for (let i = 0; i < arr.length; i++) {
          if (arr[i] >= 18) {
            document.write(`成年人的年龄: ${arr[i]} <br>`)
          }
        }
        //3
        let sum = 0
        for (let i = 0; i < arr.length; i++) {
          sum += arr[i]
        }
        document.write(`<br>所有人总年龄: ${sum} <br>`)
        //4
        let average=sum/arr.length
        document.write(`<br>所有人的平均年龄: ${average} <br>`)
        //5
        let max=arr[0]
        let min=arr[0]
         for (let i = 1; i < arr.length; i++) {
          if (max < arr[i]) {
            max = arr[i]
          }
          if (min > arr[i]) {
            min = arr[i]
          }
        }
        document.write(`<br>最大年龄: ${max} <br>最小年龄: ${min} <br>`)
    </script>
  </body>
</html>
